{include file="public/_header" /}

<div class="x-body">
    <a title="添加Banner" class="layui-btn layui-btn layui-btn-mini "
       onclick="addBanner('添加Banner','{:url('banner/add')}',900,500)"
    >
        <i class="layui-icon">添加Banner</i>
    </a>

    <a class="layui-btn layui-btn-small" class="layui-btn layui-btn layui-btn-mini " style="float: right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i>
    </a>

    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <form action="" method="post" class="ajax-form">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th style="width: 15px;"><input type="checkbox" class="check-all"></th>
                        <th>ID</th>
                        <th>图片</th>
                        <th>跳转链接</th>
                        <th>是否显示</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody class="tr-data">
                    {volist name="data" id="vo"}
                    <tr>
                        <td><input type="checkbox" name="ids[]" value="{$vo.id}"></td>
                        <td>{$vo.id}</td>
                        <th><img src="{$vo.img}" alt="" width="70px"></th>
                        <td>{$vo.url}</td>

                        <td class="layui-form">
                            <input type="checkbox" name="status" value="{$vo.id}" lay-skin="switch"
                                   lay-text="ON|OFF" lay-filter="changeStatus"
                                   {if $vo.status== 1}
                                   checked
                                   {/if}
                            >
                        </td>
                        <td>{$vo.create_time|date="Y/m/d",###}</td>
                        <td class="td-manage">

                            <a title="编辑" class="layui-btn layui-btn layui-btn-mini "
                               onclick="addBanner('添加Banner','{:url('banner/edit',['id'=>$vo.id])}',900,500)"
                               href="javascript:;">
                                <i class="layui-icon">编辑</i>
                            </a>


                            <a href="{:url('admin/banner/delete',['id'=>$vo['id']])}"
                               class="layui-btn layui-btn-danger layui-btn-mini ajax-delete">删除</a>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
                <button type="button" class="layui-btn layui-btn-danger layui-btn-small ajax-action"
                        data-action="{:url('admin/banner/delete')}">删除
                </button>
                <span>&ensp;</span>第{$data->currentPage()}页&nbsp;&nbsp;共{$data->total()}条
            </form>
        </div>
        <div class="page" style="float:  right">
            {$data->render()}
        </div>
    </div>

    {include file="public/_footer" /}
    <script>

        /**
         * 通用批量处理（审核、取消审核、删除）
         */
        $('.ajax-action').on('click', function () {
            var _action = $(this).data('action');
            layer.open({
                shade: false,
                content: '确定执行此操作？',
                btn: ['确定', '取消'],
                yes: function (index) {
                    $.ajax({
                        url: _action,
                        data: $('.ajax-form').serialize(),
                        success: function (info) {
                            if (info.code === 1) {
                                setTimeout(function () {
                                    location.href = info.url;
                                }, 1000);
                            }
                            layer.msg(info.msg);
                        }
                    });
                    layer.close(index);
                }
            });

            return false;
        });

        /**
         * 通用全选
         */

        $('body').on('click', '.check-all', function () {
            $(this).parents('table').find('input[type="checkbox"]').prop('checked', $(this).prop('checked'));
        });


        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });
        });


        layui.use(['form', 'layer'], function () {
            $ = layui.jquery;
            var form = layui.form
                    , layer = layui.layer;
            var util = layui.util;

            //监听指定开关
            form.on('switch(changeStatus)', function (data) {

                url = "/admin/banner/updateOnlineType";
                var id = data.value;
                var status = 0;
                if (data.elem.checked == true) {
                    status = 1;
                } else {
                    status = 0;
                }
                $.ajax({
                    type: "post",
                    url: url,
                    data: {
                        status: status,
                        id: id,
                    },
                    dataType: 'json',
                    success: function (data) {
                        if (data.status != 1) {
                            alert("修改失败");
                        }
                    }
                });
            });
        });


        /**
         * @param title 标题
         * @param url 请求的url
         * @param w 弹出层宽度（缺省调默认值）
         * @param h 弹出层高度（缺省调默认值）
         */
        function addBanner(title, url, w, h) {
            if (title == null || title == '') {
                title = false;
            }
            ;
            if (url == null || url == '') {
                url = "404.html";
            }
            ;
            if (w == null || w == '') {
                w = ($(window).width() * 0.9);
            }
            ;
            if (h == null || h == '') {
                h = ($(window).height() - 50);
            }
            ;
            layer.open({
                type: 2,
                area: [w + 'px', h + 'px'],
                fix: false, //不固定
                maxmin: true,
                shadeClose: true,
                shade: 0.4,
                title: title,
                content: url,
                end: function () {
                    javascript:location.replace(location.href);
                }
            });


        }

    </script>


    <script>var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();</script>

